<template>
<!--pages/map/map.wxml-->
<map id="myMap" style="width: 100%; height:100vh;" :latitude="latitude" :longitude="longitude" :markers="markers" :covers="covers" show-location></map>
</template>

<script>
// pages/map/map.js
//获取应用实例
const app = getApp();
function bMapTransQQMap(lng, lat) {
  let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  let x = lng - 0.0065;
  let y = lat - 0.006;
  let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  let lngs = z * Math.cos(theta);
  let lats = z * Math.sin(theta);
  return {
    lng: lngs,
    lat: lats
  };
}

export default {
  data() {
    return {
      covers: "",
      markers: "",
      longitude: "",
      latitude: ""
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (opt) {
    let qqLocal = bMapTransQQMap(opt.lng, opt.lat);
    let flag = opt.flag;

    if (flag == "摆摊地址") {
      this.setData({
        latitude: opt.lat,
        longitude: opt.lng,
        markers: [{
          latitude: opt.lat,
          longitude: opt.lng,
          iconPath: "/static/images/dwl.png",
          label: {
            content: opt.title + "\r\n摆摊地址: " + opt.addr + "\r\n开放时间: " + (opt.time ? opt.time : '暂无相关信息'),
            bgColor: "#fff",
            fontSize: '30rpx',
            padding: "15rpx",
            borderRadius: "20rpx",
            borderWidth: "5rpx",
            borderColor: "#ff6600",
            textAlign: 'left',
            anchorX: -130,
            anchorY: -85
          }
        }]
      });
    } else if (flag == "九价疫苗") {
      this.setData({
        latitude: opt.lat,
        longitude: opt.lng,
        markers: [{
          latitude: opt.lat,
          longitude: opt.lng,
          iconPath: "/static/images/dwl.png",
          label: {
            content: "点位地址: " + opt.addr + "\r\n预约电话: " + (opt.tel ? opt.tel : '暂无相关信息'),
            bgColor: "#fff",
            fontSize: '30rpx',
            padding: "15rpx",
            borderRadius: "20rpx",
            borderWidth: "5rpx",
            borderColor: "#ff6600",
            textAlign: 'left',
            anchorX: -130,
            anchorY: -85
          }
        }]
      });
    } else this.setData({
      latitude: qqLocal.lat,
      longitude: qqLocal.lng,
      markers: [{
        latitude: qqLocal.lat,
        longitude: qqLocal.lng,
        iconPath: "/static/images/dwl.png",
        label: {
          content: "地址: " + opt.addr + "\r\n预约电话: " + (opt.tel ? opt.tel : '暂无相关信息'),
          bgColor: "#fff",
          fontSize: '30rpx',
          padding: "15rpx",
          borderRadius: "20rpx",
          borderWidth: "5rpx",
          borderColor: "#ff6600",
          textAlign: 'left',
          anchorX: 130,
          anchorY: -105
        }
      }]
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {}
};
</script>
<style>
/* pages/map/map.wxss */
</style>